package cn.rongdao.jrkabao.dao;

import com.mifengkong.frtools.util.FRString;
import com.mifengkong.greendao.bean.CityInfo;

import java.util.List;


/**
 * Created by jack on 2017/8/26
 */

public class CityDao extends BaseDao<CityInfo> {

    public static CityDao getInstance() {
        return getPresent(CityDao.class);
    }

    public boolean isHaveCityInfo() {
        return !(FRString.isEmpty(getCityId()) || FRString.isEmpty(getCityName()));
    }

    public CityInfo getCityInfo() {
        List<CityInfo> cityInfoList = queryAll(CityInfo.class);
        if (null != cityInfoList && cityInfoList.size() > 0) {
            return cityInfoList.get(0);
        }
        return null;
    }

    public String getCityId() {
        if (null != getCityInfo()) {
            return FRString.valueOf(getCityInfo().getCity_id());
        }
        return FRString.EMPTY_STRING;
    }

    public String getCityName() {
        if (null != getCityInfo()) {
            return FRString.valueOf(getCityInfo().getCity_name());
        }
        return FRString.EMPTY_STRING;
    }

    public void updateCityId(String cityId) {
        if (FRString.isEmpty(cityId)) {
            return;
        }
        CityInfo cityInfo = getCityInfo();
        cityInfo.setCity_id(cityId);
        updateObject(cityInfo);
    }

    public void updateCityIdAndName(String cityId, String cityName) {
        if (FRString.isEmpty(cityId) || FRString.isEmpty(cityName)) {
            return;
        }
        CityInfo cityInfo = getCityInfo();
        cityInfo.setCity_id(cityId);
        cityInfo.setCity_name(cityName);
        updateObject(cityInfo);
    }

    public void updateCityName(String cityName) {
        if (FRString.isEmpty(cityName)) {
            return;
        }
        CityInfo cityInfo = getCityInfo();
        cityInfo.setCity_name(cityName);
        updateObject(cityInfo);
    }
}
